Help Emma count gift combinations that match the donation target
Help Emma count the number of different gift item combinations that sum exactly to the donation target, then apply her event rule (count * 2 + 10).
Values:
Output: 4
18
(Subsets: [1,2,4], [1,3,3], [2,5], [3,4])
Output: 3
16
(Subsets: [2,4,10], [4,12], [6,10])
| Value \ Sum | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| 2 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 3 | 1 | 1 | 1 | 2 | 1 | 1 | 1 |
Count: 1, Result: 1 * 2 + 10 = 12 (Subset: [3,3])
For filling the DP table
For the DP table
Example 1: values = [1, 2, 3, 4, 5, 6], target = 7 → 4
18
Example 2: values = [2, 4, 6, 10, 12], target = 16 → 3
16
For filling the DP table
For the DP table